package com.example.kotlinExample

import com.example.kotlinExample.entity.Book
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
import java.util.*


/**
 *
 *
 * @author liliang
 */
@RunWith(SpringRunner::class)
@SpringBootTest
class EsTest {

    @Autowired
    private lateinit var bookService: EsService

    @Test
    fun testAll() {
        t1AddOne()
        t2AddBatch()
        Thread.sleep(1000)
        t3FindAll()
        t4search()
        t5deleteOne()
        t6deleteBatch()
        Thread.sleep(1000)
        t7FindAll()
    }

    @Test
    fun t1AddOne() {
        val putOne = bookService.putOne(Book(1, "西游记"))
        println("【1】putOne：$putOne")
    }

    @Test
    fun t2AddBatch() {
        val list: MutableList<Book> = ArrayList<Book>()
        list.add(Book(2, "水浒传"))
        list.add(Book(3, "三国演义"))
        val putBatch = bookService.putBatch(list)
        println("【2】putBatch：" + putBatch.status())
    }

    @Test
    fun t3FindAll() {
        println("【3】")
        val res: List<Book> = bookService.getAll()
        println("↓↓↓findAll")
        res.forEach(System.out::println)
        println("↑↑↑findAll")
    }

    @Test
    fun t4search() {
        println("【4】")
        val searchByKey: List<Book?> = bookService.searchByKey("水传")
        searchByKey.forEach(System.out::println)
        val book: Book? = bookService.getByBookId(2)
        println("【4】getByBookId：$book")
    }

    @Test
    fun t5deleteOne() {
        val deleteById = bookService.deleteById(1)
        println("【5】deleteById：" + deleteById!!.status)
    }

    @Test
    fun t6deleteBatch() {
        val ids: MutableList<Int> = ArrayList()
        ids.add(2)
        ids.add(3)
        val deleteBatch = bookService.deleteBatch(ids)
        println("【6】deleteBatch：" + deleteBatch.status())
    }

    @Test
    fun t7FindAll() {
        println("【7】")
        val res: List<Book> = bookService.getAll()
        println("↓↓↓findAll")
        res.forEach(System.out::println)
        println("↑↑↑findAll")
    }
}